package gui;

import file.SettingsDefinition;
import gui.bf3.BF3CheckBox;
import gui.bf3.BF3ComboBox;
import gui.bf3.BF3Setting;
import gui.bf3.BF3Slider;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import transparent.TransparentPanel;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class GamePlaySettingsPanel extends TransparentPanel {


	/**
	 * 
	 */
	private static final long serialVersionUID = 1663772453647861464L;
	
	private static final int PANEL_WIDTH = 415;
	private static final int CONTROLS_PANEL_HEIGHT = 155;
	private static final int PADGAMPLAY_PANEL_HEIGHT = 75;
	private static final int GAMEPLAY_PANEL_HEIGHT = 190;


	
	
	private BF3ComboBox verticalLook;
	private BF3ComboBox verticalFlight;
	private BF3Slider mouseSensitivity;
	private BF3CheckBox mouseRawInput;
	private BF3ComboBox zoomMode;
	private BF3ComboBox crouchMode;
	private BF3CheckBox enableSubtitles;
	private BF3CheckBox hintSystem;
	private BF3CheckBox reloadHint;
	private BF3CheckBox allowPunkbuster;
	private BF3CheckBox vibration;
	private BF3CheckBox aimAssist;

	public GamePlaySettingsPanel(List<BF3Setting> settings) {
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

		// Controls Panel
		JPanel controlsPanel = new TransparentPanel();
		controlsPanel.setPreferredSize(new Dimension(PANEL_WIDTH, CONTROLS_PANEL_HEIGHT));
		controlsPanel.setMaximumSize(new Dimension(PANEL_WIDTH, CONTROLS_PANEL_HEIGHT));
		controlsPanel.setMinimumSize(new Dimension(PANEL_WIDTH, CONTROLS_PANEL_HEIGHT));
		controlsPanel.setBorder(BorderFactory.createTitledBorder("Controls"));
		controlsPanel.setLayout(new BoxLayout(controlsPanel, BoxLayout.Y_AXIS));
		
		JPanel controlsSubPanel1 = new TransparentPanel(new GridLayout(2, 2, 0, 5));
		controlsPanel.add(controlsSubPanel1);
		
		
		controlsSubPanel1.add(new JLabel("Vertical Look"));
		verticalLook = new BF3ComboBox(new SettingsDefinition[]{SettingsDefinition.SCHEME0FLIPY, SettingsDefinition.SCHEME1FLIPY}, new String[]  { "Normal", "Inverted" });
		settings.add(verticalLook);
		verticalLook.setActionCommand("verticalLook");
		verticalLook.addActionListener(new GamePlayActionListener());
		controlsSubPanel1.add(verticalLook);

		controlsSubPanel1.add(new JLabel("Vertical Flight"));
		verticalFlight = new BF3ComboBox(SettingsDefinition.SCHEME2FLIPY, new String[] { "Normal", "Inverted" });
		settings.add(verticalFlight);
		verticalFlight.setActionCommand("verticalFlight");
		controlsSubPanel1.add(verticalFlight);

		JPanel controlsSubPanel2 = new TransparentPanel(new GridLayout(1, 2, 0, 5));
		controlsPanel.add(controlsSubPanel2);
		
		controlsSubPanel2.add(new JLabel("Mouse Sensitivity"));
		mouseSensitivity = new BF3Slider(SettingsDefinition.MOUSESENSITIVITY);
		mouseSensitivity.addChangeListener(new GamePlayChangeListener());
		settings.add(mouseSensitivity);
		controlsSubPanel2.add(mouseSensitivity);

		JPanel controlsSubPanel3 = new TransparentPanel(new GridLayout(1, 2, 0, 5));
		controlsPanel.add(controlsSubPanel3);
		
		controlsSubPanel3.add(new JLabel("Raw Mouse Input"));
		mouseRawInput = new BF3CheckBox(SettingsDefinition.MOUSERAWINPUT);
		mouseRawInput.addActionListener(new GamePlayActionListener());
		settings.add(mouseRawInput);
		controlsSubPanel3.add(mouseRawInput);

		// Gameplay Panel
		JPanel gamePlayPanel = new TransparentPanel();
		gamePlayPanel.setPreferredSize(new Dimension(PANEL_WIDTH, GAMEPLAY_PANEL_HEIGHT));
		gamePlayPanel.setMaximumSize(new Dimension(PANEL_WIDTH, GAMEPLAY_PANEL_HEIGHT));
		gamePlayPanel.setMinimumSize(new Dimension(PANEL_WIDTH, GAMEPLAY_PANEL_HEIGHT));
		gamePlayPanel.setBorder(BorderFactory.createTitledBorder("General"));
		gamePlayPanel.setLayout(new GridLayout(6, 2, 0, 5));

		gamePlayPanel.add(new JLabel("Zoom"));
		zoomMode = new BF3ComboBox(SettingsDefinition.ZOOMTOGGLE, new String[]  {"Hold Button" , "Click Button" });
		zoomMode.addActionListener(new GamePlayActionListener());
		settings.add(zoomMode);
		gamePlayPanel.add(zoomMode);

		gamePlayPanel.add(new JLabel("Crouch"));
		crouchMode = new BF3ComboBox(SettingsDefinition.CROUCHTOGGLE, new String[] {"Hold Button" , "Click Button" });
		crouchMode.addActionListener(new GamePlayActionListener());
		settings.add(crouchMode);
		gamePlayPanel.add(crouchMode);

		gamePlayPanel.add(new JLabel("Enable Subtitles"));
		enableSubtitles = new BF3CheckBox(SettingsDefinition.ENABLESUBTITLES);
		enableSubtitles.addActionListener(new GamePlayActionListener());
		settings.add(enableSubtitles);
		gamePlayPanel.add(enableSubtitles);

		gamePlayPanel.add(new JLabel("Enable Hint System"));
		hintSystem = new BF3CheckBox(SettingsDefinition.HINTSYSTEM);
		hintSystem.addActionListener(new GamePlayActionListener());
		settings.add(hintSystem);
		gamePlayPanel.add(hintSystem);

		gamePlayPanel.add(new JLabel("Enable Reload Hint"));
		reloadHint = new BF3CheckBox(SettingsDefinition.RELOADHINT);
		reloadHint.addActionListener(new GamePlayActionListener());
		settings.add(reloadHint);
		gamePlayPanel.add(reloadHint);

		gamePlayPanel.add(new JLabel("Allow Punkbuster"));
		allowPunkbuster = new BF3CheckBox(SettingsDefinition.ALLOWPUNKBUSTER);
		allowPunkbuster.addActionListener(new GamePlayActionListener());
		settings.add(allowPunkbuster);
		gamePlayPanel.add(allowPunkbuster);

		// Gamepad Panel
		JPanel padGamplayPanel = new TransparentPanel();
		padGamplayPanel.setPreferredSize(new Dimension(PANEL_WIDTH, PADGAMPLAY_PANEL_HEIGHT));
		padGamplayPanel.setMaximumSize(new Dimension(PANEL_WIDTH, PADGAMPLAY_PANEL_HEIGHT));
		padGamplayPanel.setMinimumSize(new Dimension(PANEL_WIDTH, PADGAMPLAY_PANEL_HEIGHT));
		padGamplayPanel.setBorder(BorderFactory.createTitledBorder("Game Pad"));
		padGamplayPanel.setLayout(new GridLayout(2, 2, 0, 5));

		padGamplayPanel.add(new JLabel("Enable Vibration"));
		vibration = new BF3CheckBox(SettingsDefinition.VIBRATION);
		vibration.addActionListener(new GamePlayActionListener());
		settings.add(vibration);
		padGamplayPanel.add(vibration);

		padGamplayPanel.add(new JLabel("Enable Aim Assist"));
		aimAssist = new BF3CheckBox(SettingsDefinition.AIMASSIST);
		aimAssist.addActionListener(new GamePlayActionListener());
		settings.add(aimAssist);
		padGamplayPanel.add(aimAssist);

		this.add(controlsPanel);
		this.add(gamePlayPanel);
		this.add(padGamplayPanel);

	}
	private class GamePlayActionListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			if(e.getSource() == verticalLook){
				verticalLook.setValue(verticalLook.getSelectedIndex()+","+verticalLook.getSelectedIndex());
			}else if (e.getSource() instanceof BF3ComboBox) {
				BF3ComboBox cb = (BF3ComboBox) e.getSource();
					cb.setValue(String.valueOf(cb.getSelectedIndex()));
					
				
			} else if (e.getSource() instanceof BF3CheckBox) {
				BF3CheckBox cb = (BF3CheckBox) e.getSource();
				if (cb.isSelected()) {
					cb.setValue("1");
				} else {
					cb.setValue("0");
				}
			}

		}
	}
	private class  GamePlayChangeListener implements ChangeListener {

		@Override
		public void stateChanged(ChangeEvent e) {
				if (e.getSource() instanceof BF3Slider) {
				BF3Slider sl = (BF3Slider) e.getSource();
				sl.setValue(String.valueOf(sl.getValue()));
			}

		}
	}
    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        Color ppColor = new Color(16, 16, 16, 100); //r,g,b,alpha
        g.setColor(ppColor);
        g.fillRect(+2,-2,PANEL_WIDTH-4,GAMEPLAY_PANEL_HEIGHT+CONTROLS_PANEL_HEIGHT+PADGAMPLAY_PANEL_HEIGHT); //x,y,width,height
    }    
}
